const defaultGantConfig = {
  readonly: false,
  xml_date: "%Y-%m-%d",
  marker: true,
  auto_scheduling: true,
  end_date: new Date(),
  scale_height: 90,
  sort: true,
  work_time: true,
  row_height: 35,
  bar_height: 35,
  show_links: false
};
class VueGantt {
  constructor({ id, gantt, task }) {
    this.id = id;
    this.gantt = gantt; // 全局gant
    this.task = task;
  }

  setGantConfig(data) {
    const target = { ...defaultGantConfig, ...data };
    for (const key in target) {
      this.gantt.config[key] = target[key];
    }
  }

  setPlugins({ marker }) {
    if (marker) {
      this.gantt.plugins({
        marker: true,
        tooltip: true,
        auto_scheduling: true,
        multiselect: true,
        fullscreen: true
      });
    }
  }

  init(gantConfig) {
    this.setGantConfig(gantConfig);
    this.setPlugins(this.gantt.config);
    this.gantt.init(this.id);
    this.gantt.parse(this.task);
    return this;
  }

  getLinks() {
    return this.gantt.getLinks();
  }

  getDataTaskStore() {
    const task = this.gantt.getDatastore("task");
    if (task.pull) {
      return Object.values(task.pull);
    }
    return [];
  }

  render() {
    this.gantt.render();
  }
}
export default VueGantt;
